<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>CPP11ThreadPool: threadpoolexecutor.hpp 源文件</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="CPP.png"/></td>
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">CPP11ThreadPool
   </div>
   <div id="projectbrief">C++11线程池</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- 制作者 Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'搜索');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('',true,false,'search.php','搜索');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
</div><!-- top -->
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">threadpoolexecutor.hpp</div>  </div>
</div><!--header-->
<div class="contents">
<div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;<span class="preprocessor">#ifndef THREADPOOLEXECUTOR_HPP</span></div><div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;<span class="preprocessor">#define THREADPOOLEXECUTOR_HPP</span></div><div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;</div><div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;<span class="preprocessor">#include &lt;future&gt;</span></div><div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;<span class="preprocessor">#include &lt;vector&gt;</span></div><div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;</div><div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160;<span class="preprocessor">#include &quot;thread.hpp&quot;</span></div><div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160;<span class="preprocessor">#include &quot;blockingqueue.hpp&quot;</span></div><div class="line"><a name="l00009"></a><span class="lineno">    9</span>&#160;<span class="preprocessor">#include &quot;runnable.hpp&quot;</span></div><div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160;<span class="preprocessor">#include &quot;semaphore.hpp&quot;</span></div><div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160;</div><div class="line"><a name="l00015"></a><span class="lineno"><a class="line" href="classRejectedExecutionHandler.html">   15</a></span>&#160;<span class="keyword">class </span><a class="code" href="classRejectedExecutionHandler.html">RejectedExecutionHandler</a> {</div><div class="line"><a name="l00016"></a><span class="lineno">   16</span>&#160;    <span class="keyword">public</span>:</div><div class="line"><a name="l00020"></a><span class="lineno">   20</span>&#160;        <a class="code" href="classRejectedExecutionHandler.html#ac288960546b34a9f0e7be49c32d2f929">RejectedExecutionHandler</a>() = <span class="keywordflow">default</span>;</div><div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;        <span class="keyword">virtual</span> <a class="code" href="classRejectedExecutionHandler.html#a640bb013143221dd4729b270da83ec5e">~RejectedExecutionHandler</a>() = <span class="keywordflow">default</span>;</div><div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160;</div><div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160;    <span class="keyword">public</span>:</div><div class="line"><a name="l00030"></a><span class="lineno"><a class="line" href="classRejectedExecutionHandler.html#a18d3240b63ffa8a84fa728f89c2ef1d1">   30</a></span>&#160;        <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classRejectedExecutionHandler.html#a18d3240b63ffa8a84fa728f89c2ef1d1">rejectedExecution</a>(<span class="keyword">const</span> <a class="code" href="classRunnable.html#abe8d3066c7305401d6f0aad8e70780f2">Runnable::sptr</a> r) {</div><div class="line"><a name="l00031"></a><span class="lineno">   31</span>&#160;            <span class="keywordflow">throw</span> std::logic_error(<span class="stringliteral">&quot;thread pool is not RUNNING&quot;</span>);</div><div class="line"><a name="l00032"></a><span class="lineno">   32</span>&#160;        }</div><div class="line"><a name="l00033"></a><span class="lineno">   33</span>&#160;</div><div class="line"><a name="l00037"></a><span class="lineno"><a class="line" href="classRejectedExecutionHandler.html#abb6476c7d64a7bd3111fc1a39829858b">   37</a></span>&#160;        <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classRejectedExecutionHandler.html#abb6476c7d64a7bd3111fc1a39829858b">rejectedExecution</a>(<span class="keyword">const</span> <a class="code" href="classRunnable.html">Runnable</a>&amp; r) {</div><div class="line"><a name="l00038"></a><span class="lineno">   38</span>&#160;            <span class="keywordflow">throw</span> std::logic_error(<span class="stringliteral">&quot;thread pool is not RUNNING&quot;</span>);</div><div class="line"><a name="l00039"></a><span class="lineno">   39</span>&#160;        }</div><div class="line"><a name="l00040"></a><span class="lineno">   40</span>&#160;};</div><div class="line"><a name="l00041"></a><span class="lineno">   41</span>&#160;</div><div class="line"><a name="l00045"></a><span class="lineno"><a class="line" href="classThreadPoolExecutor.html">   45</a></span>&#160;<span class="keyword">class </span><a class="code" href="classThreadPoolExecutor.html">ThreadPoolExecutor</a> {</div><div class="line"><a name="l00046"></a><span class="lineno">   46</span>&#160;    <span class="keyword">public</span>:</div><div class="line"><a name="l00059"></a><span class="lineno">   59</span>&#160;        <span class="keyword">explicit</span> <a class="code" href="classThreadPoolExecutor.html">ThreadPoolExecutor</a>(int32_t corePoolSize,</div><div class="line"><a name="l00060"></a><span class="lineno">   60</span>&#160;                                    int32_t maxPoolSize,</div><div class="line"><a name="l00061"></a><span class="lineno">   61</span>&#160;                                    <span class="keyword">const</span> std::vector&lt;<a class="code" href="classBlockingQueue.html">BlockingQueue&lt;Runnable::sptr&gt;</a>&gt;&amp; workQueue,</div><div class="line"><a name="l00062"></a><span class="lineno">   62</span>&#160;                                    <span class="keyword">const</span> <a class="code" href="classRejectedExecutionHandler.html">RejectedExecutionHandler</a>&amp; handler,</div><div class="line"><a name="l00063"></a><span class="lineno">   63</span>&#160;                                    <span class="keyword">const</span> std::string&amp; prefix = <span class="stringliteral">&quot;&quot;</span></div><div class="line"><a name="l00064"></a><span class="lineno">   64</span>&#160;                                   );</div><div class="line"><a name="l00065"></a><span class="lineno">   65</span>&#160;</div><div class="line"><a name="l00078"></a><span class="lineno">   78</span>&#160;        <span class="keyword">explicit</span> <a class="code" href="classThreadPoolExecutor.html">ThreadPoolExecutor</a>(int32_t corePoolSize,</div><div class="line"><a name="l00079"></a><span class="lineno">   79</span>&#160;                                    int32_t maxPoolSize,</div><div class="line"><a name="l00080"></a><span class="lineno">   80</span>&#160;                                    <span class="keyword">const</span> std::vector&lt;<a class="code" href="classBlockingQueue.html">BlockingQueue&lt;Runnable::sptr&gt;</a>&gt;&amp; workQueue,</div><div class="line"><a name="l00081"></a><span class="lineno">   81</span>&#160;                                    <a class="code" href="classRejectedExecutionHandler.html">RejectedExecutionHandler</a>* handler,</div><div class="line"><a name="l00082"></a><span class="lineno">   82</span>&#160;                                    <span class="keyword">const</span> std::string&amp; prefix = <span class="stringliteral">&quot;&quot;</span></div><div class="line"><a name="l00083"></a><span class="lineno">   83</span>&#160;                                   );</div><div class="line"><a name="l00084"></a><span class="lineno">   84</span>&#160;</div><div class="line"><a name="l00095"></a><span class="lineno">   95</span>&#160;        <span class="keyword">explicit</span> <a class="code" href="classThreadPoolExecutor.html">ThreadPoolExecutor</a>(int32_t corePoolSize,</div><div class="line"><a name="l00096"></a><span class="lineno">   96</span>&#160;                                    int32_t maxPoolSize,</div><div class="line"><a name="l00097"></a><span class="lineno">   97</span>&#160;                                    <span class="keyword">const</span> std::string&amp; prefix = <span class="stringliteral">&quot;&quot;</span>);</div><div class="line"><a name="l00098"></a><span class="lineno">   98</span>&#160;</div><div class="line"><a name="l00102"></a><span class="lineno">  102</span>&#160;        <span class="keyword">virtual</span> ~<a class="code" href="classThreadPoolExecutor.html">ThreadPoolExecutor</a> ();</div><div class="line"><a name="l00103"></a><span class="lineno">  103</span>&#160;</div><div class="line"><a name="l00104"></a><span class="lineno">  104</span>&#160;    <span class="keyword">public</span>:</div><div class="line"><a name="l00111"></a><span class="lineno">  111</span>&#160;        <span class="keyword">virtual</span> <span class="keywordtype">bool</span> keepNonCoreThreadAlive () <span class="keyword">const</span> <span class="keyword">final</span>;</div><div class="line"><a name="l00112"></a><span class="lineno">  112</span>&#160;</div><div class="line"><a name="l00118"></a><span class="lineno">  118</span>&#160;        <span class="keyword">virtual</span> <span class="keywordtype">void</span> keepNonCoreThreadAlive(<span class="keywordtype">bool</span> value) <span class="keyword">final</span>;</div><div class="line"><a name="l00119"></a><span class="lineno">  119</span>&#160;</div><div class="line"><a name="l00127"></a><span class="lineno">  127</span>&#160;        <span class="keyword">virtual</span> <span class="keywordtype">void</span> releaseNonCoreThreads();</div><div class="line"><a name="l00128"></a><span class="lineno">  128</span>&#160;</div><div class="line"><a name="l00134"></a><span class="lineno">  134</span>&#160;        <span class="keyword">virtual</span> <span class="keywordtype">void</span> setRejectedExecutionHandler(<a class="code" href="classRejectedExecutionHandler.html">RejectedExecutionHandler</a> handler) <span class="keyword">final</span>;</div><div class="line"><a name="l00135"></a><span class="lineno">  135</span>&#160;</div><div class="line"><a name="l00149"></a><span class="lineno">  149</span>&#160;        <span class="keywordtype">bool</span> execute(<a class="code" href="classRunnable.html#abe8d3066c7305401d6f0aad8e70780f2">Runnable::sptr</a> command, <span class="keywordtype">bool</span> core = <span class="keyword">true</span>);</div><div class="line"><a name="l00150"></a><span class="lineno">  150</span>&#160;</div><div class="line"><a name="l00165"></a><span class="lineno">  165</span>&#160;        <span class="keyword">virtual</span> <span class="keywordtype">bool</span> execute(<a class="code" href="classRunnable.html">Runnable</a>&amp; command, <span class="keywordtype">bool</span> core = <span class="keyword">true</span>);</div><div class="line"><a name="l00166"></a><span class="lineno">  166</span>&#160;</div><div class="line"><a name="l00179"></a><span class="lineno">  179</span>&#160;        <span class="keyword">virtual</span> <span class="keywordtype">bool</span> execute(<a class="code" href="classBlockingQueue.html">BlockingQueue&lt;Runnable::sptr&gt;</a>&amp; commands, <span class="keywordtype">bool</span> core = <span class="keyword">true</span>);</div><div class="line"><a name="l00180"></a><span class="lineno">  180</span>&#160;</div><div class="line"><a name="l00193"></a><span class="lineno">  193</span>&#160;        <span class="keyword">template</span>&lt;<span class="keyword">typename</span> F&gt;</div><div class="line"><a name="l00194"></a><span class="lineno">  194</span>&#160;        std::future&lt;typename std::result_of&lt;F()&gt;::type&gt;</div><div class="line"><a name="l00195"></a><span class="lineno"><a class="line" href="classThreadPoolExecutor.html#a94834ab6bedcc75111524fec4e928b3f">  195</a></span>&#160;        <a class="code" href="classThreadPoolExecutor.html#a94834ab6bedcc75111524fec4e928b3f">submit</a>(F f, <span class="keywordtype">bool</span> core = <span class="keyword">true</span>) {</div><div class="line"><a name="l00196"></a><span class="lineno">  196</span>&#160;            <span class="keyword">using</span> result_type = <span class="keyword">typename</span> std::result_of&lt;F()&gt;::type;</div><div class="line"><a name="l00197"></a><span class="lineno">  197</span>&#160;            std::packaged_task&lt;result_type()&gt; task(std::move(f));</div><div class="line"><a name="l00198"></a><span class="lineno">  198</span>&#160;            std::future&lt;result_type&gt; res(task.get_future());</div><div class="line"><a name="l00199"></a><span class="lineno">  199</span>&#160;            <span class="keywordflow">if</span>(addWorker(<a class="code" href="classRunnable.html">Runnable</a>(std::move(task)), core)) {</div><div class="line"><a name="l00200"></a><span class="lineno">  200</span>&#160;            } <span class="keywordflow">else</span> {</div><div class="line"><a name="l00201"></a><span class="lineno">  201</span>&#160;                <span class="keywordtype">int</span> c = ctl_.load();</div><div class="line"><a name="l00202"></a><span class="lineno">  202</span>&#160;                <span class="keywordflow">if</span> (!isRunning(c)) {</div><div class="line"><a name="l00203"></a><span class="lineno">  203</span>&#160;                    reject(<a class="code" href="classRunnable.html">Runnable</a>(std::move(task)));</div><div class="line"><a name="l00204"></a><span class="lineno">  204</span>&#160;                }</div><div class="line"><a name="l00205"></a><span class="lineno">  205</span>&#160;            }</div><div class="line"><a name="l00206"></a><span class="lineno">  206</span>&#160;            <span class="keywordflow">return</span> res;</div><div class="line"><a name="l00207"></a><span class="lineno">  207</span>&#160;        }</div><div class="line"><a name="l00208"></a><span class="lineno">  208</span>&#160;</div><div class="line"><a name="l00214"></a><span class="lineno">  214</span>&#160;        <span class="keyword">virtual</span> std::string toString() <span class="keyword">const</span>;</div><div class="line"><a name="l00215"></a><span class="lineno">  215</span>&#160;</div><div class="line"><a name="l00222"></a><span class="lineno">  222</span>&#160;        <span class="keyword">virtual</span> <span class="keywordtype">int</span> getActiveCount() <span class="keyword">const</span> <span class="keyword">final</span>;</div><div class="line"><a name="l00223"></a><span class="lineno">  223</span>&#160;</div><div class="line"><a name="l00229"></a><span class="lineno">  229</span>&#160;        <span class="keyword">virtual</span> <span class="keywordtype">long</span> getTaskCount() <span class="keyword">const</span>;</div><div class="line"><a name="l00230"></a><span class="lineno">  230</span>&#160;</div><div class="line"><a name="l00238"></a><span class="lineno">  238</span>&#160;        <span class="keyword">virtual</span> <span class="keywordtype">void</span> setMaxPoolSize(<span class="keywordtype">int</span> maxPoolSize) <span class="keyword">final</span>;</div><div class="line"><a name="l00239"></a><span class="lineno">  239</span>&#160;</div><div class="line"><a name="l00245"></a><span class="lineno">  245</span>&#160;        <span class="keyword">virtual</span> <span class="keywordtype">int</span> getEverPoolSize() <span class="keyword">const</span> <span class="keyword">final</span>;</div><div class="line"><a name="l00246"></a><span class="lineno">  246</span>&#160;</div><div class="line"><a name="l00252"></a><span class="lineno">  252</span>&#160;        <span class="keyword">virtual</span> <span class="keywordtype">int</span> getCorePoolSize() <span class="keyword">const</span> <span class="keyword">final</span>;</div><div class="line"><a name="l00253"></a><span class="lineno">  253</span>&#160;</div><div class="line"><a name="l00258"></a><span class="lineno">  258</span>&#160;        <span class="keyword">virtual</span> <span class="keywordtype">void</span> shutdown() <span class="keyword">final</span>;</div><div class="line"><a name="l00259"></a><span class="lineno">  259</span>&#160;</div><div class="line"><a name="l00263"></a><span class="lineno">  263</span>&#160;        <span class="keyword">virtual</span> <span class="keywordtype">void</span> stop() <span class="keyword">final</span>;</div><div class="line"><a name="l00264"></a><span class="lineno">  264</span>&#160;</div><div class="line"><a name="l00270"></a><span class="lineno">  270</span>&#160;        <span class="keyword">virtual</span> <span class="keywordtype">bool</span> isShutDown() <span class="keyword">final</span>;</div><div class="line"><a name="l00271"></a><span class="lineno">  271</span>&#160;</div><div class="line"><a name="l00277"></a><span class="lineno">  277</span>&#160;        <span class="keyword">virtual</span> <span class="keywordtype">bool</span> isTerminated() <span class="keyword">final</span>;</div><div class="line"><a name="l00278"></a><span class="lineno">  278</span>&#160;</div><div class="line"><a name="l00285"></a><span class="lineno">  285</span>&#160;        <span class="keyword">virtual</span> <span class="keywordtype">int</span> preStartCoreThreads();</div><div class="line"><a name="l00286"></a><span class="lineno">  286</span>&#160;</div><div class="line"><a name="l00292"></a><span class="lineno"><a class="line" href="classThreadPoolExecutor.html#a14c4e3d786dcf22e858b11a95d2f77ef">  292</a></span>&#160;        <span class="keyword">virtual</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classThreadPoolExecutor.html#a14c4e3d786dcf22e858b11a95d2f77ef">reject</a>(<span class="keyword">const</span> <a class="code" href="classRunnable.html">Runnable</a> &amp; command) <span class="keyword">final</span> {</div><div class="line"><a name="l00293"></a><span class="lineno">  293</span>&#160;            rejectHandler_-&gt;rejectedExecution(command);</div><div class="line"><a name="l00294"></a><span class="lineno">  294</span>&#160;        }</div><div class="line"><a name="l00295"></a><span class="lineno">  295</span>&#160;</div><div class="line"><a name="l00296"></a><span class="lineno">  296</span>&#160;    <span class="keyword">protected</span>:</div><div class="line"><a name="l00300"></a><span class="lineno"><a class="line" href="classThreadPoolExecutor.html#a61774315237123faf8e7fcc9d35ae47d">  300</a></span>&#160;        <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classThreadPoolExecutor.html#a61774315237123faf8e7fcc9d35ae47d">terminated</a>() {}</div><div class="line"><a name="l00301"></a><span class="lineno">  301</span>&#160;</div><div class="line"><a name="l00302"></a><span class="lineno">  302</span>&#160;    <span class="keyword">protected</span>:</div><div class="line"><a name="l00306"></a><span class="lineno">  306</span>&#160;        <span class="keyword">virtual</span> <span class="keywordtype">void</span> releaseWorkers();</div><div class="line"><a name="l00307"></a><span class="lineno">  307</span>&#160;</div><div class="line"><a name="l00315"></a><span class="lineno"><a class="line" href="classThreadPoolExecutor.html#acdb626fdcb6ed4c7822508d1e0a3fcf5">  315</a></span>&#160;        <span class="keyword">virtual</span> <span class="keyword">inline</span> <span class="keywordtype">int</span> <a class="code" href="classThreadPoolExecutor.html#acdb626fdcb6ed4c7822508d1e0a3fcf5">runStateOf</a>(int32_t c) <span class="keyword">const</span> <span class="keyword">final</span> {</div><div class="line"><a name="l00316"></a><span class="lineno">  316</span>&#160;            <span class="keywordflow">return</span> c &amp; ~CAPACITY;</div><div class="line"><a name="l00317"></a><span class="lineno">  317</span>&#160;        }</div><div class="line"><a name="l00318"></a><span class="lineno">  318</span>&#160;</div><div class="line"><a name="l00326"></a><span class="lineno"><a class="line" href="classThreadPoolExecutor.html#a4f842d070a584bbc16a693207a947aac">  326</a></span>&#160;        <span class="keyword">virtual</span> <span class="keyword">inline</span> <span class="keywordtype">int</span> <a class="code" href="classThreadPoolExecutor.html#a4f842d070a584bbc16a693207a947aac">workerCountOf</a>(int32_t c) <span class="keyword">const</span> <span class="keyword">final</span> {</div><div class="line"><a name="l00327"></a><span class="lineno">  327</span>&#160;            <span class="keywordflow">return</span> c &amp; CAPACITY;</div><div class="line"><a name="l00328"></a><span class="lineno">  328</span>&#160;        }</div><div class="line"><a name="l00329"></a><span class="lineno">  329</span>&#160;</div><div class="line"><a name="l00338"></a><span class="lineno"><a class="line" href="classThreadPoolExecutor.html#a31ed7a73571c79c8dbb486f27a4df4eb">  338</a></span>&#160;        <span class="keyword">virtual</span> <span class="keyword">inline</span> int32_t <a class="code" href="classThreadPoolExecutor.html#a31ed7a73571c79c8dbb486f27a4df4eb">ctlOf</a>(int32_t rs, int32_t wc) <span class="keyword">const</span> <span class="keyword">final</span> {</div><div class="line"><a name="l00339"></a><span class="lineno">  339</span>&#160;            <span class="keywordflow">return</span> rs | wc;</div><div class="line"><a name="l00340"></a><span class="lineno">  340</span>&#160;        }</div><div class="line"><a name="l00341"></a><span class="lineno">  341</span>&#160;</div><div class="line"><a name="l00350"></a><span class="lineno">  350</span>&#160;        <span class="keyword">virtual</span> <span class="keywordtype">bool</span> addWorker(<a class="code" href="classRunnable.html">Runnable</a> task, <span class="keywordtype">bool</span> core = <span class="keyword">true</span>);</div><div class="line"><a name="l00351"></a><span class="lineno">  351</span>&#160;</div><div class="line"><a name="l00360"></a><span class="lineno">  360</span>&#160;        <span class="keyword">virtual</span> <span class="keywordtype">bool</span> addWorker(<a class="code" href="classRunnable.html#abe8d3066c7305401d6f0aad8e70780f2">Runnable::sptr</a> task, <span class="keywordtype">bool</span> core = <span class="keyword">true</span>);</div><div class="line"><a name="l00361"></a><span class="lineno">  361</span>&#160;</div><div class="line"><a name="l00367"></a><span class="lineno">  367</span>&#160;        <span class="keyword">virtual</span> <span class="keywordtype">void</span> advanceRunState(int32_t targetState) <span class="keyword">final</span>;</div><div class="line"><a name="l00368"></a><span class="lineno">  368</span>&#160;</div><div class="line"><a name="l00374"></a><span class="lineno">  374</span>&#160;        <span class="keyword">virtual</span> <span class="keywordtype">void</span> coreWorkerThread(<span class="keywordtype">size_t</span> queueIdex);</div><div class="line"><a name="l00375"></a><span class="lineno">  375</span>&#160;</div><div class="line"><a name="l00381"></a><span class="lineno">  381</span>&#160;        <span class="keyword">virtual</span> <span class="keywordtype">void</span> workerThread(<span class="keywordtype">size_t</span> queueIdex);</div><div class="line"><a name="l00382"></a><span class="lineno">  382</span>&#160;</div><div class="line"><a name="l00388"></a><span class="lineno"><a class="line" href="classThreadPoolExecutor.html#a353e65b77bb3c0950ed79939473d4852">  388</a></span>&#160;        <span class="keyword">virtual</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classThreadPoolExecutor.html#a353e65b77bb3c0950ed79939473d4852">reject</a>(<span class="keyword">const</span> <a class="code" href="classRunnable.html#abe8d3066c7305401d6f0aad8e70780f2">Runnable::sptr</a> command) <span class="keyword">final</span> {</div><div class="line"><a name="l00389"></a><span class="lineno">  389</span>&#160;            rejectHandler_-&gt;rejectedExecution(command);</div><div class="line"><a name="l00390"></a><span class="lineno">  390</span>&#160;        }</div><div class="line"><a name="l00391"></a><span class="lineno">  391</span>&#160;</div><div class="line"><a name="l00399"></a><span class="lineno"><a class="line" href="classThreadPoolExecutor.html#a841ae2189d6f85b9df9f69dec5375341">  399</a></span>&#160;        <span class="keyword">virtual</span> <span class="keyword">inline</span> <span class="keywordtype">bool</span> <a class="code" href="classThreadPoolExecutor.html#a841ae2189d6f85b9df9f69dec5375341">isRunning</a>(<span class="keywordtype">int</span> c) <span class="keyword">const</span> <span class="keyword">final</span> {</div><div class="line"><a name="l00400"></a><span class="lineno">  400</span>&#160;            <span class="keywordflow">return</span> c &lt; SHUTDOWN;</div><div class="line"><a name="l00401"></a><span class="lineno">  401</span>&#160;        }</div><div class="line"><a name="l00402"></a><span class="lineno">  402</span>&#160;</div><div class="line"><a name="l00411"></a><span class="lineno"><a class="line" href="classThreadPoolExecutor.html#aa12a3efb879080453fb7abc486585698">  411</a></span>&#160;        <span class="keyword">virtual</span> <span class="keyword">inline</span> <span class="keywordtype">bool</span> <a class="code" href="classThreadPoolExecutor.html#aa12a3efb879080453fb7abc486585698">runStateLessThan</a>(<span class="keywordtype">int</span> c, <span class="keywordtype">int</span> s)<span class="keyword">const</span> <span class="keyword">final</span> {</div><div class="line"><a name="l00412"></a><span class="lineno">  412</span>&#160;            <span class="keywordflow">return</span> c &lt; s;</div><div class="line"><a name="l00413"></a><span class="lineno">  413</span>&#160;        }</div><div class="line"><a name="l00414"></a><span class="lineno">  414</span>&#160;</div><div class="line"><a name="l00423"></a><span class="lineno"><a class="line" href="classThreadPoolExecutor.html#a44ee48ed44faa12fc6373074e9059e4e">  423</a></span>&#160;        <span class="keyword">virtual</span> <span class="keyword">inline</span> <span class="keywordtype">bool</span> <a class="code" href="classThreadPoolExecutor.html#a44ee48ed44faa12fc6373074e9059e4e">runStateAtLeast</a>(<span class="keywordtype">int</span> c, <span class="keywordtype">int</span> s)<span class="keyword">const</span> <span class="keyword">final</span> {</div><div class="line"><a name="l00424"></a><span class="lineno">  424</span>&#160;            <span class="keywordflow">return</span> c &gt;= s;</div><div class="line"><a name="l00425"></a><span class="lineno">  425</span>&#160;        }</div><div class="line"><a name="l00426"></a><span class="lineno">  426</span>&#160;</div><div class="line"><a name="l00434"></a><span class="lineno"><a class="line" href="classThreadPoolExecutor.html#ac1bcafe65f800aeb9feade5f31b64fde">  434</a></span>&#160;        <span class="keyword">virtual</span> <span class="keywordtype">bool</span> <a class="code" href="classThreadPoolExecutor.html#ac1bcafe65f800aeb9feade5f31b64fde">compareAndIncrementWorkerCount</a>(<span class="keywordtype">int</span> expect) <span class="keyword">final</span> {</div><div class="line"><a name="l00435"></a><span class="lineno">  435</span>&#160;            <span class="keywordflow">return</span> ctl_.compare_exchange_strong(expect, expect + 1);</div><div class="line"><a name="l00436"></a><span class="lineno">  436</span>&#160;        }</div><div class="line"><a name="l00437"></a><span class="lineno">  437</span>&#160;</div><div class="line"><a name="l00445"></a><span class="lineno"><a class="line" href="classThreadPoolExecutor.html#ac40053b88cd669526a0a6225b5e1a86e">  445</a></span>&#160;        <span class="keyword">virtual</span> <span class="keywordtype">bool</span> <a class="code" href="classThreadPoolExecutor.html#ac40053b88cd669526a0a6225b5e1a86e">compareAndDecrementWorkerCount</a>(<span class="keywordtype">int</span> expect)<span class="keyword">final</span> {</div><div class="line"><a name="l00446"></a><span class="lineno">  446</span>&#160;            <span class="keywordflow">return</span> ctl_.compare_exchange_weak(expect, expect - 1);</div><div class="line"><a name="l00447"></a><span class="lineno">  447</span>&#160;        }</div><div class="line"><a name="l00448"></a><span class="lineno">  448</span>&#160;</div><div class="line"><a name="l00453"></a><span class="lineno"><a class="line" href="classThreadPoolExecutor.html#ab19dcfa8af5864274e66bccf40255484">  453</a></span>&#160;        <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classThreadPoolExecutor.html#ab19dcfa8af5864274e66bccf40255484">decrementWorkerCount</a>() {</div><div class="line"><a name="l00454"></a><span class="lineno">  454</span>&#160;            <span class="keywordflow">do</span> {</div><div class="line"><a name="l00455"></a><span class="lineno">  455</span>&#160;</div><div class="line"><a name="l00456"></a><span class="lineno">  456</span>&#160;            } <span class="keywordflow">while</span> (!compareAndDecrementWorkerCount(ctl_.load()));</div><div class="line"><a name="l00457"></a><span class="lineno">  457</span>&#160;        }</div><div class="line"><a name="l00458"></a><span class="lineno">  458</span>&#160;</div><div class="line"><a name="l00459"></a><span class="lineno">  459</span>&#160;    <span class="keyword">protected</span>:</div><div class="line"><a name="l00461"></a><span class="lineno"><a class="line" href="classThreadPoolExecutor.html#af82bff422304406f59a14b5b638c2b42">  461</a></span>&#160;        <span class="keyword">const</span> int32_t COUNT_BITS = 29;</div><div class="line"><a name="l00463"></a><span class="lineno"><a class="line" href="classThreadPoolExecutor.html#aac96b726327ad0d07709085ab49c4f58">  463</a></span>&#160;        <span class="keyword">const</span> int32_t CAPACITY   = (1 &lt;&lt; COUNT_BITS) - 1;</div><div class="line"><a name="l00465"></a><span class="lineno"><a class="line" href="classThreadPoolExecutor.html#a9e28d5aa0cb4500921f7244565b8bed8">  465</a></span>&#160;        <span class="keyword">const</span> int32_t RUNNING    = (-1 &lt;&lt; COUNT_BITS);</div><div class="line"><a name="l00467"></a><span class="lineno"><a class="line" href="classThreadPoolExecutor.html#aa0958f2bf040bf2f199c629ec9145b44">  467</a></span>&#160;        <span class="keyword">const</span> int32_t SHUTDOWN   = 0 &lt;&lt; COUNT_BITS;</div><div class="line"><a name="l00469"></a><span class="lineno"><a class="line" href="classThreadPoolExecutor.html#ae3c0ff657b3c0d8bbaf7f10bfdf587ca">  469</a></span>&#160;        <span class="keyword">const</span> int32_t STOP       = 1 &lt;&lt; COUNT_BITS;</div><div class="line"><a name="l00471"></a><span class="lineno"><a class="line" href="classThreadPoolExecutor.html#a3d2a0964f6bce420433491da80000c4c">  471</a></span>&#160;        <span class="keyword">const</span> int32_t TIDYING    = 2 &lt;&lt; COUNT_BITS;</div><div class="line"><a name="l00473"></a><span class="lineno"><a class="line" href="classThreadPoolExecutor.html#a15bb29c714876435f3c59cd0137ac074">  473</a></span>&#160;        <span class="keyword">const</span> int32_t TERMINATED = 3 &lt;&lt; COUNT_BITS;</div><div class="line"><a name="l00474"></a><span class="lineno">  474</span>&#160;</div><div class="line"><a name="l00476"></a><span class="lineno"><a class="line" href="classThreadPoolExecutor.html#ac4496adc7a7ff18b97464a863fcf4a73">  476</a></span>&#160;        <span class="keywordtype">int</span>                                                          <a class="code" href="classThreadPoolExecutor.html#ac4496adc7a7ff18b97464a863fcf4a73">corePoolSize_</a>;</div><div class="line"><a name="l00478"></a><span class="lineno"><a class="line" href="classThreadPoolExecutor.html#a7fb9fd51e0a4b27277012c16596b9137">  478</a></span>&#160;        <span class="keywordtype">int</span>                                                          <a class="code" href="classThreadPoolExecutor.html#a7fb9fd51e0a4b27277012c16596b9137">maxPoolSize_</a>;</div><div class="line"><a name="l00480"></a><span class="lineno"><a class="line" href="classThreadPoolExecutor.html#a32da434f74911bcc1702eaafabfac368">  480</a></span>&#160;        <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>                                                 submitId_{0};</div><div class="line"><a name="l00482"></a><span class="lineno"><a class="line" href="classThreadPoolExecutor.html#acf28232c8314da96403992137fdd1c2f">  482</a></span>&#160;        std::string                                                  <a class="code" href="classThreadPoolExecutor.html#acf28232c8314da96403992137fdd1c2f">prefix_</a>;</div><div class="line"><a name="l00484"></a><span class="lineno"><a class="line" href="classThreadPoolExecutor.html#a2c8fc052c3760c89bf5198409d8c9c72">  484</a></span>&#160;        <span class="keyword">volatile</span> <span class="keywordtype">bool</span>                                                keepNonCoreThreadAlive_{<span class="keyword">false</span>};</div><div class="line"><a name="l00486"></a><span class="lineno"><a class="line" href="classThreadPoolExecutor.html#ad8f4e68f28d617749537036f6e688b8c">  486</a></span>&#160;        std::atomic&lt;int&gt;                                             everPoolSize_{0};</div><div class="line"><a name="l00488"></a><span class="lineno"><a class="line" href="classThreadPoolExecutor.html#a2ef0eea2a8ca7a03bd9d361ced31f71b">  488</a></span>&#160;        <span class="keyword">mutable</span> std::mutex                                           <a class="code" href="classThreadPoolExecutor.html#a2ef0eea2a8ca7a03bd9d361ced31f71b">mutex_</a>;</div><div class="line"><a name="l00490"></a><span class="lineno"><a class="line" href="classThreadPoolExecutor.html#a010113b7aac17ef364d417c485263873">  490</a></span>&#160;        std::atomic_int32_t                                          <a class="code" href="classThreadPoolExecutor.html#a010113b7aac17ef364d417c485263873">ctl_</a>;</div><div class="line"><a name="l00492"></a><span class="lineno"><a class="line" href="classThreadPoolExecutor.html#ad523af8548ca8f1dae80cb295ee567b3">  492</a></span>&#160;        std::condition_variable                                      <a class="code" href="classThreadPoolExecutor.html#ad523af8548ca8f1dae80cb295ee567b3">notEmpty_</a>;</div><div class="line"><a name="l00494"></a><span class="lineno"><a class="line" href="classThreadPoolExecutor.html#a47dd74330fa41d01067943b1db74818a">  494</a></span>&#160;        std::vector&lt;Thread::sptr&gt;                                    <a class="code" href="classThreadPoolExecutor.html#a47dd74330fa41d01067943b1db74818a">threads_</a>;</div><div class="line"><a name="l00496"></a><span class="lineno"><a class="line" href="classThreadPoolExecutor.html#a415491f8f40c0fcb99e7ec25cdd209d0">  496</a></span>&#160;        std::vector&lt;BlockingQueue&lt;Runnable::sptr&gt;&gt;                   <a class="code" href="classThreadPoolExecutor.html#a415491f8f40c0fcb99e7ec25cdd209d0">workQueues_</a>;</div><div class="line"><a name="l00498"></a><span class="lineno"><a class="line" href="classThreadPoolExecutor.html#a347041db412b03aa09dd4e9b3beaa391">  498</a></span>&#160;        std::unique_ptr&lt;RejectedExecutionHandler&gt;                    <a class="code" href="classThreadPoolExecutor.html#a347041db412b03aa09dd4e9b3beaa391">rejectHandler_</a>;</div><div class="line"><a name="l00499"></a><span class="lineno">  499</span>&#160;</div><div class="line"><a name="l00500"></a><span class="lineno">  500</span>&#160;};</div><div class="line"><a name="l00501"></a><span class="lineno">  501</span>&#160;</div><div class="line"><a name="l00502"></a><span class="lineno">  502</span>&#160;<span class="preprocessor">#endif </span><span class="comment">/* THREADPOOLEXECUTOR_HPP */</span><span class="preprocessor"></span></div><div class="ttc" id="classThreadPoolExecutor_html_a415491f8f40c0fcb99e7ec25cdd209d0"><div class="ttname"><a href="classThreadPoolExecutor.html#a415491f8f40c0fcb99e7ec25cdd209d0">ThreadPoolExecutor::workQueues_</a></div><div class="ttdeci">std::vector&lt; BlockingQueue&lt; Runnable::sptr &gt; &gt; workQueues_</div><div class="ttdoc">任务队列 </div><div class="ttdef"><b>Definition:</b> threadpoolexecutor.hpp:496</div></div>
<div class="ttc" id="classRejectedExecutionHandler_html_a18d3240b63ffa8a84fa728f89c2ef1d1"><div class="ttname"><a href="classRejectedExecutionHandler.html#a18d3240b63ffa8a84fa728f89c2ef1d1">RejectedExecutionHandler::rejectedExecution</a></div><div class="ttdeci">virtual void rejectedExecution(const Runnable::sptr r)</div><div class="ttdoc">拒绝策略的执行函数 </div><div class="ttdef"><b>Definition:</b> threadpoolexecutor.hpp:30</div></div>
<div class="ttc" id="classThreadPoolExecutor_html_a2ef0eea2a8ca7a03bd9d361ced31f71b"><div class="ttname"><a href="classThreadPoolExecutor.html#a2ef0eea2a8ca7a03bd9d361ced31f71b">ThreadPoolExecutor::mutex_</a></div><div class="ttdeci">std::mutex mutex_</div><div class="ttdoc">队列锁 </div><div class="ttdef"><b>Definition:</b> threadpoolexecutor.hpp:488</div></div>
<div class="ttc" id="classThreadPoolExecutor_html_a4f842d070a584bbc16a693207a947aac"><div class="ttname"><a href="classThreadPoolExecutor.html#a4f842d070a584bbc16a693207a947aac">ThreadPoolExecutor::workerCountOf</a></div><div class="ttdeci">virtual int workerCountOf(int32_t c) const final</div><div class="ttdoc">workerCountOf 得到工作线程数量 </div><div class="ttdef"><b>Definition:</b> threadpoolexecutor.hpp:326</div></div>
<div class="ttc" id="classThreadPoolExecutor_html_a47dd74330fa41d01067943b1db74818a"><div class="ttname"><a href="classThreadPoolExecutor.html#a47dd74330fa41d01067943b1db74818a">ThreadPoolExecutor::threads_</a></div><div class="ttdeci">std::vector&lt; Thread::sptr &gt; threads_</div><div class="ttdoc">线程队列 </div><div class="ttdef"><b>Definition:</b> threadpoolexecutor.hpp:494</div></div>
<div class="ttc" id="classRejectedExecutionHandler_html_a640bb013143221dd4729b270da83ec5e"><div class="ttname"><a href="classRejectedExecutionHandler.html#a640bb013143221dd4729b270da83ec5e">RejectedExecutionHandler::~RejectedExecutionHandler</a></div><div class="ttdeci">virtual ~RejectedExecutionHandler()=default</div><div class="ttdoc">~RejectedExecutionHandler 析构函数 </div></div>
<div class="ttc" id="classThreadPoolExecutor_html_acf28232c8314da96403992137fdd1c2f"><div class="ttname"><a href="classThreadPoolExecutor.html#acf28232c8314da96403992137fdd1c2f">ThreadPoolExecutor::prefix_</a></div><div class="ttdeci">std::string prefix_</div><div class="ttdoc">线程名前缀 </div><div class="ttdef"><b>Definition:</b> threadpoolexecutor.hpp:482</div></div>
<div class="ttc" id="classThreadPoolExecutor_html_a841ae2189d6f85b9df9f69dec5375341"><div class="ttname"><a href="classThreadPoolExecutor.html#a841ae2189d6f85b9df9f69dec5375341">ThreadPoolExecutor::isRunning</a></div><div class="ttdeci">virtual bool isRunning(int c) const final</div><div class="ttdoc">isRunning 是否还在运行 </div><div class="ttdef"><b>Definition:</b> threadpoolexecutor.hpp:399</div></div>
<div class="ttc" id="classThreadPoolExecutor_html_a353e65b77bb3c0950ed79939473d4852"><div class="ttname"><a href="classThreadPoolExecutor.html#a353e65b77bb3c0950ed79939473d4852">ThreadPoolExecutor::reject</a></div><div class="ttdeci">virtual void reject(const Runnable::sptr command) final</div><div class="ttdoc">reject 将任务抛弃 </div><div class="ttdef"><b>Definition:</b> threadpoolexecutor.hpp:388</div></div>
<div class="ttc" id="classThreadPoolExecutor_html_ac4496adc7a7ff18b97464a863fcf4a73"><div class="ttname"><a href="classThreadPoolExecutor.html#ac4496adc7a7ff18b97464a863fcf4a73">ThreadPoolExecutor::corePoolSize_</a></div><div class="ttdeci">int corePoolSize_</div><div class="ttdoc">核心线程数 </div><div class="ttdef"><b>Definition:</b> threadpoolexecutor.hpp:476</div></div>
<div class="ttc" id="classThreadPoolExecutor_html_ad523af8548ca8f1dae80cb295ee567b3"><div class="ttname"><a href="classThreadPoolExecutor.html#ad523af8548ca8f1dae80cb295ee567b3">ThreadPoolExecutor::notEmpty_</a></div><div class="ttdeci">std::condition_variable notEmpty_</div><div class="ttdoc">队列非空条件变量 </div><div class="ttdef"><b>Definition:</b> threadpoolexecutor.hpp:492</div></div>
<div class="ttc" id="classThreadPoolExecutor_html_ac1bcafe65f800aeb9feade5f31b64fde"><div class="ttname"><a href="classThreadPoolExecutor.html#ac1bcafe65f800aeb9feade5f31b64fde">ThreadPoolExecutor::compareAndIncrementWorkerCount</a></div><div class="ttdeci">virtual bool compareAndIncrementWorkerCount(int expect) final</div><div class="ttdoc">compareAndIncrementWorkerCount 尝试CAS递增ctl的workerCount字段. </div><div class="ttdef"><b>Definition:</b> threadpoolexecutor.hpp:434</div></div>
<div class="ttc" id="classThreadPoolExecutor_html_a347041db412b03aa09dd4e9b3beaa391"><div class="ttname"><a href="classThreadPoolExecutor.html#a347041db412b03aa09dd4e9b3beaa391">ThreadPoolExecutor::rejectHandler_</a></div><div class="ttdeci">std::unique_ptr&lt; RejectedExecutionHandler &gt; rejectHandler_</div><div class="ttdoc">拒绝策略回调 </div><div class="ttdef"><b>Definition:</b> threadpoolexecutor.hpp:498</div></div>
<div class="ttc" id="classThreadPoolExecutor_html_ab19dcfa8af5864274e66bccf40255484"><div class="ttname"><a href="classThreadPoolExecutor.html#ab19dcfa8af5864274e66bccf40255484">ThreadPoolExecutor::decrementWorkerCount</a></div><div class="ttdeci">virtual void decrementWorkerCount()</div><div class="ttdoc">decrementWorkerCount 减少ctl的workerCount字段 </div><div class="ttdef"><b>Definition:</b> threadpoolexecutor.hpp:453</div></div>
<div class="ttc" id="classThreadPoolExecutor_html_aa12a3efb879080453fb7abc486585698"><div class="ttname"><a href="classThreadPoolExecutor.html#aa12a3efb879080453fb7abc486585698">ThreadPoolExecutor::runStateLessThan</a></div><div class="ttdeci">virtual bool runStateLessThan(int c, int s) const final</div><div class="ttdoc">runStateLessThan 状态低于 </div><div class="ttdef"><b>Definition:</b> threadpoolexecutor.hpp:411</div></div>
<div class="ttc" id="classRejectedExecutionHandler_html"><div class="ttname"><a href="classRejectedExecutionHandler.html">RejectedExecutionHandler</a></div><div class="ttdoc">不再接受任务时的拒绝策略 </div><div class="ttdef"><b>Definition:</b> threadpoolexecutor.hpp:15</div></div>
<div class="ttc" id="classThreadPoolExecutor_html_a31ed7a73571c79c8dbb486f27a4df4eb"><div class="ttname"><a href="classThreadPoolExecutor.html#a31ed7a73571c79c8dbb486f27a4df4eb">ThreadPoolExecutor::ctlOf</a></div><div class="ttdeci">virtual int32_t ctlOf(int32_t rs, int32_t wc) const final</div><div class="ttdoc">ctlOf 控制变量初始化 </div><div class="ttdef"><b>Definition:</b> threadpoolexecutor.hpp:338</div></div>
<div class="ttc" id="classRejectedExecutionHandler_html_abb6476c7d64a7bd3111fc1a39829858b"><div class="ttname"><a href="classRejectedExecutionHandler.html#abb6476c7d64a7bd3111fc1a39829858b">RejectedExecutionHandler::rejectedExecution</a></div><div class="ttdeci">virtual void rejectedExecution(const Runnable &amp;r)</div><div class="ttdoc">拒绝策略的执行函数 </div><div class="ttdef"><b>Definition:</b> threadpoolexecutor.hpp:37</div></div>
<div class="ttc" id="classThreadPoolExecutor_html_a61774315237123faf8e7fcc9d35ae47d"><div class="ttname"><a href="classThreadPoolExecutor.html#a61774315237123faf8e7fcc9d35ae47d">ThreadPoolExecutor::terminated</a></div><div class="ttdeci">virtual void terminated()</div><div class="ttdoc">terminated 线程池终止时执行 </div><div class="ttdef"><b>Definition:</b> threadpoolexecutor.hpp:300</div></div>
<div class="ttc" id="classThreadPoolExecutor_html_a010113b7aac17ef364d417c485263873"><div class="ttname"><a href="classThreadPoolExecutor.html#a010113b7aac17ef364d417c485263873">ThreadPoolExecutor::ctl_</a></div><div class="ttdeci">std::atomic_int32_t ctl_</div><div class="ttdoc">控制变量 </div><div class="ttdef"><b>Definition:</b> threadpoolexecutor.hpp:490</div></div>
<div class="ttc" id="classRunnable_html_abe8d3066c7305401d6f0aad8e70780f2"><div class="ttname"><a href="classRunnable.html#abe8d3066c7305401d6f0aad8e70780f2">Runnable::sptr</a></div><div class="ttdeci">std::shared_ptr&lt; Runnable &gt; sptr</div><div class="ttdoc">std::shared_ptr&lt;Runnable&gt;别名 </div><div class="ttdef"><b>Definition:</b> runnable.hpp:18</div></div>
<div class="ttc" id="classThreadPoolExecutor_html"><div class="ttname"><a href="classThreadPoolExecutor.html">ThreadPoolExecutor</a></div><div class="ttdoc">线程池基本实现,每个线程都有一个任务队列 </div><div class="ttdef"><b>Definition:</b> threadpoolexecutor.hpp:45</div></div>
<div class="ttc" id="classRunnable_html"><div class="ttname"><a href="classRunnable.html">Runnable</a></div><div class="ttdoc">Runnable interface 重写operator()或传进lambda </div><div class="ttdef"><b>Definition:</b> runnable.hpp:13</div></div>
<div class="ttc" id="classThreadPoolExecutor_html_ac40053b88cd669526a0a6225b5e1a86e"><div class="ttname"><a href="classThreadPoolExecutor.html#ac40053b88cd669526a0a6225b5e1a86e">ThreadPoolExecutor::compareAndDecrementWorkerCount</a></div><div class="ttdeci">virtual bool compareAndDecrementWorkerCount(int expect) final</div><div class="ttdoc">compareAndDecrementWorkerCount 尝试CAS递减ctl的workerCount字段. </div><div class="ttdef"><b>Definition:</b> threadpoolexecutor.hpp:445</div></div>
<div class="ttc" id="classThreadPoolExecutor_html_a7fb9fd51e0a4b27277012c16596b9137"><div class="ttname"><a href="classThreadPoolExecutor.html#a7fb9fd51e0a4b27277012c16596b9137">ThreadPoolExecutor::maxPoolSize_</a></div><div class="ttdeci">int maxPoolSize_</div><div class="ttdoc">最大线程数 </div><div class="ttdef"><b>Definition:</b> threadpoolexecutor.hpp:478</div></div>
<div class="ttc" id="classBlockingQueue_html"><div class="ttname"><a href="classBlockingQueue.html">BlockingQueue</a></div><div class="ttdoc">BlockingQueue 阻塞队列(FIFO) </div><div class="ttdef"><b>Definition:</b> blockingqueue.hpp:14</div></div>
<div class="ttc" id="classThreadPoolExecutor_html_acdb626fdcb6ed4c7822508d1e0a3fcf5"><div class="ttname"><a href="classThreadPoolExecutor.html#acdb626fdcb6ed4c7822508d1e0a3fcf5">ThreadPoolExecutor::runStateOf</a></div><div class="ttdeci">virtual int runStateOf(int32_t c) const final</div><div class="ttdoc">runStateOf 得到线程池状态 </div><div class="ttdef"><b>Definition:</b> threadpoolexecutor.hpp:315</div></div>
<div class="ttc" id="classThreadPoolExecutor_html_a44ee48ed44faa12fc6373074e9059e4e"><div class="ttname"><a href="classThreadPoolExecutor.html#a44ee48ed44faa12fc6373074e9059e4e">ThreadPoolExecutor::runStateAtLeast</a></div><div class="ttdeci">virtual bool runStateAtLeast(int c, int s) const final</div><div class="ttdoc">runStateAtLeast 运行状态最少是 </div><div class="ttdef"><b>Definition:</b> threadpoolexecutor.hpp:423</div></div>
<div class="ttc" id="classThreadPoolExecutor_html_a94834ab6bedcc75111524fec4e928b3f"><div class="ttname"><a href="classThreadPoolExecutor.html#a94834ab6bedcc75111524fec4e928b3f">ThreadPoolExecutor::submit</a></div><div class="ttdeci">std::future&lt; typename std::result_of&lt; F()&gt;::type &gt; submit(F f, bool core=true)</div><div class="ttdoc">submit 在将来某个时候执行给定的任务, 任务可以在新线程或现有的合并的线程中执行, 可以有返回值,向任务队列提交的是任务副本 会抛出异常 </div><div class="ttdef"><b>Definition:</b> threadpoolexecutor.hpp:195</div></div>
<div class="ttc" id="classThreadPoolExecutor_html_a14c4e3d786dcf22e858b11a95d2f77ef"><div class="ttname"><a href="classThreadPoolExecutor.html#a14c4e3d786dcf22e858b11a95d2f77ef">ThreadPoolExecutor::reject</a></div><div class="ttdeci">virtual void reject(const Runnable &amp;command) final</div><div class="ttdoc">reject 将任务抛弃 </div><div class="ttdef"><b>Definition:</b> threadpoolexecutor.hpp:292</div></div>
<div class="ttc" id="classRejectedExecutionHandler_html_ac288960546b34a9f0e7be49c32d2f929"><div class="ttname"><a href="classRejectedExecutionHandler.html#ac288960546b34a9f0e7be49c32d2f929">RejectedExecutionHandler::RejectedExecutionHandler</a></div><div class="ttdeci">RejectedExecutionHandler()=default</div><div class="ttdoc">RejectedExecutionHandler 构造函数 </div></div>
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
制作者 &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.13
</small></address>
</body>
</html>
